<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h1>待办事项</h1>
    <input type="text" v-model="thing">
    <button @click="add">添加</button>
    <p>待完成事项</p>
    <ol>
      <li v-for="(item, index) in todoThings">
        {{item}}
        <button @click="del(index)">del</button>
      </li>
    </ol>
    <p>已完成事项</p>
    <ol>
      <li v-for="item in doneThings">
        {{item}}
      </li>
    </ol>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <!-- 2.写自己的vue代码 -->
  <script>
    let vm = new Vue({
      el: '#app',
      data() {
        return {
          // 要添加的事项
          thing: '',
          // 待完成的数组
          todoThings: [],
          // 待完成的数组
          doneThings: []
        }
      },
      methods: {
        add() {
          // 判断，不为空时才能添加
          if(this.thing) {
            this.todoThings.push(this.thing);
            // 将输入框清空
            this.thing = '';
          }
        },
        del(index) {
          // 向已完成中添加，需要先添，否则index会不准确
          this.doneThings.push(this.todoThings[index]);
          // 从待完成中删除
          this.todoThings.splice(index, 1);
        }
      },
    })
  </script>
</body>
</html>